package com.findviewbydream.evil.helloyouth.Utils;

import android.os.Handler;
import android.os.Message;

/********************************************
 * 工程名：FreshmenGuide
 * 包名：edu.hebeu.evil.freshmenguide.Utils
 * 时间：16-7-4 下午9:35
 * 作者：白雨濃 evil
 * 邮箱：evilbai@foxmail.com
 * 内容：
 ********************************************/
public abstract class SHandler
{
    public abstract void handler();

    public void thread()
    {
    }

    public void thread(Handler handler)
    {
    }

    public void startByCustom()
    {
        final Handler handler = new Handler()
        {
            @Override
            public void handleMessage(Message msg)
            {
                super.handleMessage(msg);
                handler();
            }
        };
        Thread thread = new Thread(new Runnable()
        {
            @Override
            public void run()
            {
                thread(handler);
            }
        });
        thread.start();
    }

    public void start()
    {
        final Handler handler = new Handler()
        {
            @Override
            public void handleMessage(Message msg)
            {
                super.handleMessage(msg);
                handler();
            }
        };
        Thread thread = new Thread(new Runnable()
        {
            @Override
            public void run()
            {
                thread();
                handler.sendEmptyMessage(0);
            }
        });
        thread.start();
    }

    public void start(final int sleepTime)
    {
        final Handler handler = new Handler()
        {
            @Override
            public void handleMessage(Message msg)
            {
                super.handleMessage(msg);
                handler();
            }
        };
        Thread thread = new Thread(new Runnable()
        {
            @Override
            public void run()
            {
                try
                {
                    Thread.sleep(sleepTime);
                }
                catch (InterruptedException e)
                {
                    e.printStackTrace();
                }
                thread();
                handler.sendEmptyMessage(0);
            }
        });
        thread.start();
    }
}
